from rest_framework import serializers
from .models import MessageModel, GroupModel


class MessageSerializer(serializers.ModelSerializer):
    uploader = serializers.SerializerMethodField()
    words = serializers.SerializerMethodField()

    class Meta:
        model = MessageModel
        fields = ['id', 'content', 'label1', 'prob1', 'label2', 'prob2', 'uploader', 'create_time', 'remark','words']

    def get_uploader(self, obj):
        return obj.uploader.first_name
    def get_words(self,obj):
        return obj.words.split(' ')


class GroupSerializer(serializers.ModelSerializer):
    name = serializers.SerializerMethodField()

    class Meta:
        model = GroupModel
        fields = ['id', 'name']

    def get_name(self, obj):
        return obj.group.name
